import urllib.request, urllib.parse

# urlencode 应用场景:多个参数的时候

# 请求地址
url = 'https://www.baidu.com/s?'

# UA 信息
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}

data = {
    'wd': '周杰伦',
    'sex': '男'
}

new_data = urllib.parse.urlencode(data)


# 请求对象定制
request = urllib.request.Request(url=url+new_data, headers=headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

content = response.read().decode('utf8')

print(content)
